<template>
	<div>
		<el-row :gutter="24">
			<el-col :span="2">
				<p class="queryLabel">编号或名称:</p>
			</el-col>
			<el-col :span="5">
				<el-input v-model="inputsearch" size="small" placeholder="请输入内容"></el-input>
			</el-col>
			<el-col :span="2">
				<el-button type="primary" size="small" @click="leconfquery">搜索</el-button>
			</el-col>
			<el-col :span="15" style="text-align: right;margin-right:-10px;">
				<el-button type="primary" size="small" @click='leconfAdd'>新增</el-button>
				<el-button type="primary" size="small" @click.native.prevent="leconfEdit">编辑</el-button>
				<el-button type="primary" size="small" @click.native.prevent="leconfstart">启用</el-button>
				<el-button type="primary" size="small" @click.native.prevent="leconfstop">停用</el-button>
			</el-col>
		</el-row>
		<el-row>
			<el-col :span="24">
				<el-table ref="multipleTable" :data="tableData.dataList" border style="width: 100%" @selection-change="handleSelectionChange">
					<el-table-column type="selection" width="55">
					</el-table-column>
					<el-table-column prop="levelCode" label="等级编号">
					</el-table-column>
					<el-table-column prop="levelName" label="等级名称">
					</el-table-column>
					<el-table-column prop="scoreType" label="评级类型" :formatter="converscoreType">
					</el-table-column>
					<el-table-column prop="itemName" label="评级项" :formatter="converitemName">
					</el-table-column>
					<el-table-column prop="countType" label="评级方式" :formatter="convercountType">
					</el-table-column>
					<el-table-column prop="countValue" label="评级值" :formatter="scoreValue">
					</el-table-column>
					<el-table-column prop="status" label="状态" :formatter="timeFormates">
					</el-table-column>
				</el-table>
				<el-pagination small @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="CurentPage" :page-sizes="page.pageSizes" :page-size="page.pageSize" layout=" total,prev, pager, next" :total="tableData.total">
				</el-pagination>
			</el-col>
		</el-row>
		<el-dialog v-model="dialogform">
			<el-form :model="dataFormModelData" label-width="120px" ref="datamodelForm" :rules="modelRule">
				<el-form-item label="选择等级:" prop="levelCode" label-width="120px">
					<el-select size="small" v-model="dataFormModelData.levelCode" placeholder="选择等级">
						<el-option v-for="item in levelCombo" :label="item.label" :value="item.value">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="评级类型:" prop="scoreType" label-width="120px">
					<el-select size="small" v-model="dataFormModelData.scoreType" placeholder="评级类型">
						<el-option v-for="item in scoreTypeArr" :label="item.label" :value="item.value">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="评级项:" prop="scoreItem" label-width="120px" v-if="dataFormModelData.scoreType=='0203040102'">
					<el-select size="small" v-model="dataFormModelData.scoreItem" placeholder="评级项">
						<el-option v-for="item in convertCom" :label="item.label" :value="item.value">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="评级方式:" prop="countType" label-width="120px">
					<el-select size="small" v-model="dataFormModelData.countType" placeholder="评级方式">
						<el-option v-for="item in countTypeArr" :label="item.label" :value="item.value">
						</el-option>
					</el-select>
				</el-form-item>
				<!--<el-form-item label="评级值:"
					              prop="countValue"  label-width="100px">
	
						<el-input size="small"
						          v-model="dataFormModelData.countValue"></el-input>
					</el-form-item>-->
				<el-form-item label="评分区间开始值:" prop="start" v-if="dataFormModelData.countType" label-width="120px">
					<el-input-number v-model="dataFormModelData.start" :min="1" :max="999999" :step="0.1"></el-input-number>
				</el-form-item>
				<el-form-item label="评分区间结束值:" prop="stop" v-if="dataFormModelData.countType" label-width="120px">
					<el-input-number v-model="dataFormModelData.stop" :min="1" :max="999999" :step="0.1"></el-input-number>
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button type="primary" @click="leconfsave">提交</el-button>
				<el-button @click="dialogform = false">关闭</el-button>
			</div>
		</el-dialog>
	</div>
</template>

<script>
export default {
	data() {
		return {
			//评级方式转换数据
			typeCovert: {
				"0203040201": "等于",
				"0203040202": "大于",
				"0203040203": "小于",
				"0203040204": "大于等于",
				"0203040205": "小于等于",
				"0203040206": "在区间"
			},
			dialogform: false,
			//页码数
			CurentPage: 1,
			page: this.page,
			//分组数据
			tableData: {
				total: 0,
				dataList: []
			},
			//表单初始值
			emptyData: {
				id: '',
				levelCode: '',//等级编号
				levelName: '',//等级名
				scoreType: '',//评级类型
				scoreItem: '',//评级项
				countType: '0203040206',//评级方式
				//				countValue:'',//评级值
				start: '',
				stop: '',
				status: '1'
			},
			//表单数据
			dataFormModelData: {
				id: '',
				levelCode: '',//等级编号
				levelName: '',//等级名
				scoreType: '',//评级类型
				scoreItem: '',//评级项
				countType: '0203040206',//评级方式
				start: '',
				stop: '',
				//				countValue:'',//评级值
				status: '1'
			},
			scoreTypeArr: [],//评级类型数组
			countTypeArr: [],//评级方式数组
			countValueArr: [],//评级值
			roleNameCombo: [],//角色列表
			levelCombo: [],//等级
			convertCom: [],//评级项
			combo: [],//模板列表
			//校验规则：
			modelRule: {
				levelCode: [{
					required: true,
					message: '请选择等级名',
					trigger: 'blur'
				}],
				scoreType: [{
					required: true,
					message: '请选择评级类型',
					trigger: 'blur'
				}],
				scoreItem: [{
					required: true,
					message: '请选择评级项',
					trigger: 'blur'
				}],
				countType: [{
					required: true,
					message: '请选择评级方式',
					trigger: 'blur'
				}],
				countValue: [{
					required: true,
					message: '请填写评级值',
					trigger: 'blur'
				}]
			},
			inputsearch: "",
			formLabelWidth: '120px',
			selectarr: [],
		}
	},
	methods: {
		//列表，分页大小切换
		handleSizeChange: function () { },
		//列表,当前页切换
		handleCurrentChange: function (currentPage) {

			this.$data.CurentPage = currentPage;
			this.leconfquery();
		},
		//查询
		leconfquery: function () {
			this.$http({
				method: 'GET',
				url: this.API_ROOT + '/bc/custome/level/conf/page',
				params: {
					levelCode: this.$data.inputsearch, //查询条件
					//					itemCode:this.$data.dataFormModelData.scoreItem,
					start: this.$data.CurentPage, //页码
					limit: this.$data.page.pageSize //每页的数量
				}
			}).then(function (resp) {

				resp.data.total = parseInt(resp.data.total);
				// es5写法
				this.$data.tableData = resp.data;
			}, function (error) {
				// error
			})
		},
		//新增
		leconfAdd: function () {

			this.$data.dataRoleFormData = Object.assign(this.$data.dataFormModelData, this.$data.emptyData);
			this.$data.dialogform = true;
		},
		//保存
		leconfsave: function () {
			this.$refs.datamodelForm.validate(function (valid) {

				if (valid) {
					this.$http.post(this.API_ROOT + '/bc/custome/level/conf/save', this.$data.dataFormModelData, {
						params: {
							uid: window.localStorage.getItem("uid")
						}
					})
						.then(resp => {

							if (resp.data.success) {
								this.$message(resp.data.msg);
								this.leconfquery();
								this.$data.dataRoleFormShow = false;
							} else {
								this.$message.error(resp.data.msg);
							}
						}, resp => {

						});
				}
				return false;
			}.bind(this));
			this.$data.dialogform = false;
		},

		//编辑
		leconfEdit: function () {
			if (this.$data.selectarr.length == 1) {
				this.$http({
					method: 'GET',
					url: this.API_ROOT + '/bc/custome/level/conf/info', //url
					params: { //发送的参数
						id: this.$data.selectarr[0].id, //查询条件
					}
				}).then(function (resp) {

					this.$data.dialogform = true;
					this.$data.dataFormModelData = resp.data.data;
				}, function (error) {
					// error
				})
			} else {
				this.$message.error("请选择数据")
			}

		},
		handleSelectionChange: function (value) {

			this.$data.selectarr = value;
			if (this.$data.selectarr.length > 1) {
				this.$message.error("请选择一条数据")
			}
		},
		//启用
		leconfstart: function () {
			if (this.$data.selectarr.length == 1) {
				this.$http({
					method: 'GET',
					url: this.API_ROOT + '/bc/custome/level/conf/start', //url
					params: { //发送的参数
						id: this.$data.selectarr[0].id, //查询条件
					}
				}).then(function (resp) {

					this.$message(resp.data.msg);
					this.leconfquery();
				}, function (error) {
					// error
				})
			} else {
				this.$message.error("请选择数据")
			}
		},
		//停用
		leconfstop: function () {
			if (this.$data.selectarr.length == 1) {
				this.$http({
					method: 'GET',
					url: this.API_ROOT + '/bc/custome/level/conf/stop', //url
					params: { //发送的参数
						id: this.$data.selectarr[0].id, //查询条件
					}
				}).then(function (resp) {

					this.$message(resp.data.msg);
					this.leconfquery();
				}, function (error) {
					// error
				})
			} else {
				this.$message.error("请选择数据")
			}
		},
		timeFormates: function (row, column) {
			if (row.status == 1) return "已启用";
			return "已停用";
		},
		scoreValue: function (row, column) {//评分值转换
			return '[' + row.start + ' - ' + row.stop + ']';
		},
		//查询[等级]
		levellistQuery: function () {

			this.$http({
				method: 'POST',
				url: this.API_ROOT + '/bc/custome/level/conf/combo',
				params: {
					uid: window.localStorage.getItem("uid")
				}
			}).then(function (resp) {

				this.$data.levelCombo = resp.data;
			}, function (error) {
				// error
			})
		},
		//查询[评级项]
		convertListQuery: function () {
			this.$http({
				method: 'POST',
				url: this.API_ROOT + '/bc/custome/level/conf/comboCode'
			}).then(function (resp) {

				this.$data.convertCom = resp.data;
			}, function (error) {
				// error
			})
		},
		//评级类型转换
		converscoreType: function (row, column) {
			if (row.scoreType == '0203040101') return "得分";
			return "项目";
		},
		//评级方式转换
		convercountType: function (row, column) {
			return this.$data.typeCovert[row.countType];
		},
		converitemName: function (row, column) {

			if (row.scoreType == '0203040101') {
				return '-'
			} else {
				return row.itemName;
			}
		}

	},
	created: function () {
		this.leconfquery();
		this.levellistQuery(); //查询等级下拉列表
		this.convertListQuery();//查询模板下拉列表

		//评级类型
		this.$http.get(this.API_ROOT + '/base/dict/combo', {
			params: {
				group: "02030401"
			}
		}).then((response) => {

			this.$data.scoreTypeArr = response.data;
		}, (response) => { });

		//评级方式
		this.$http.get(this.API_ROOT + '/base/dict/combo', {
			params: {
				group: "02030402"
			}
		}).then((response) => {

			this.$data.countTypeArr = response.data;
		}, (response) => { });

	}
}
</script>

<style>

</style>